<template>
  <div>
    <el-form ref="formRef" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item prop="name" label="员工姓名:">
            <el-input v-model="userInfo.name" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="age" label="员工年龄:">
            <el-input v-model="userInfo.age" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="phone" label="员工手机号:">
            <el-input v-model="userInfo.phone" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="idNumber" label="员工身份证:">
            <el-input v-model="userInfo.idNumber" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="createTime" label="员工入职时间:" disabled>
            <el-input v-model="userInfo.createTime" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="sex" label="员工性别:">
            <el-input v-model="userInfo.sex" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="status" label="员工状态:">
            <el-input v-model="userInfo.status" placeholder="" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 按钮 -->
      <el-form-item>
        <el-row type="flex" justify="center">
          <el-col :span="16">
            <el-button size="mini" type="primary" @click="btnOk"
              >返回上一页</el-button
            >
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { employeeDetailApi } from "@/api/employee";
export default {
  data() {
    return {
      userInfo: {
        name: "",
        phone: "",
        age: "",
        createTime: "",
        id: "",
        idNumber: "",
        sex: "",
        status: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入名字", trigger: "blur" },
          {
            min: 2,
            max: 6,
            message: "姓名为2-6位",
          },
        ],
        age: [{ required: true, message: "请输入年龄", trigger: "blur" }],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "手机号格式不正确",
            trigger: "blur",
          },
        ],
        idNumber: [
          { required: true, message: "请输入用户身份证", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "请输入创建时间", trigger: "blur" },
        ],
        status: [
          { required: true, message: "请输入用户状态", trigger: "blur" },
        ],
        sex: [{ required: true, message: "请输入性别", trigger: "blur" }],
      },
    };
  },
  created() {
    if (this.$route.params.id) {
      this.employeeDetail();
    }
  },
  methods: {
    // 点击确认
    btnOk() {
      this.$router.push("/employee");
    },
    async employeeDetail() {
      const res = await employeeDetailApi(this.$route.params.id);
      this.userInfo = res.data;
    },
  },
};
</script>

<style scoped></style>
